#include <sstream>
#include <iostream>
#include <utility>
#include <string>
using namespace std; // should do this to use string cout directly


class cpw {
		private: 
			string *sp; // pay attention to the behavior of copy and return 
		public: 
			cpw(string x="default"){
				sp = new string(x);
			}
		
			cpw(const cpw& p) {
					cout << "copy constuctor ..." << endl;
					sp=new string(*(p.sp));}

			/*
			cpw& operator=(const cpw& p){
				cout << "assignment ..." << endl;
				*sp=*(p.sp);
				return (*this);
			}*/
			
			~cpw(){
				cout << "calling deconstructor ... " << endl;
				delete sp;
			}
			

		friend ostream& operator<< (ostream&, const cpw& );
};


ostream& operator<< (ostream& os, const cpw& p){
  os << *(p.sp);
  return os;
}

int main(){
	cpw c("Rong");
	cpw c1="Rong";
	/*
	for(int i=0; i<3; i++){
			cout << c1 << endl;
			c1=c1; // shadow copy causes segmentation fault, so we need to define our own copy 
			// once user defined assignment exist, no automatic coerce will be perform
	}*/
	return 0;
}
